<?php

namespace app\admin\controller\channel;

use app\admin\controller\AdminController;
use app\admin\service\channel\WechatService;
use think\response\Json;

class Wechat extends AdminController
{
    /**
     * 获取微信公众号渠道配置
     * @return Json
     */
    public function getWechatConfig()
    {
        $result = WechatService::getWechatConfig();
        return $this->data($result);
    }

    /**
     * 设置微信公众号渠道配置
     * @return Json
     */
    public function setWechatConfig()
    {
        $params = $this->postData([
            ['name', ''],
            ['original_id', ''],
            ['qr_code', ''],
            ['app_id', ''],
            ['app_secret', ''],
            ['token', ''],
            ['encoding_aes_key', ''],
            ['encryption_type', ''],
            ['verify_file_url', ''],
        ]);

        $result = WechatService::setWechatConfig($params);
        if(true === $result) {
            return $this->success([], '设置成功');
        } else {
            return $this->error(WechatService::getError());
        }
    }
}